<template>
    <div class="dialogPop">
      <el-dialog :visible.sync="updataData.dialogUpdata" :before-close="handleClose" size="tiny" title="修改学校配置">
        <el-form :model="updataData" :rules="rules" ref="updataData" label-width="90px">
          <el-row :gutter="20">
            <el-col :span="22">
              <el-form-item label="选择学校:" prop="schoolName">
                    <span>{{updataData.schoolName}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="22">
              <el-form-item label="公网IP:" prop="sNetIp">
                   <el-popover placement="top-start" trigger="focus"
                                content="字符长度不大于20个">
                      <el-input v-model="updataData.sNetIp" slot="reference" :maxlength="20"  placeholder="请输入公网IP"></el-input>
                   </el-popover>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="22">
              <el-form-item label="端口号:" prop="sPort">
                   <el-popover placement="top-start" trigger="focus"
                                content="字符长度不大于5个">
                      <el-input v-model="updataData.sPort" slot="reference" :maxlength="5"  placeholder="请输入端口号"></el-input>
                   </el-popover>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <p class="btn">
            <el-button @click="resetForm('updataData')">取 消</el-button>
            <el-button type="primary" @click="updataBtn('updataData')" :loading="loadingBtn">确 认</el-button>
          </p>
        </div>
      </el-dialog>
    </div>
</template>
<script>
import { getSettlementConfigDetail, updateSettlementConfig } from 'api/deviceManagement';
export default {
    props: {
        updataData: {
            default() {
                return {
                    dialogUpdata: false, // 默认不显示
                    pId: '',
                    schoolName: '',
                    sNetIp: '',
                    sPort: ''
                }
            },
            required: true
        }
    },
    data() {
        return {
            // formInline: {
            //     schoolName: '',
            //     sNetIp: '',
            //     sPort: ''
            // },
            loadingBtn: false,
            rules: {
                schoolName: [
                     { required: true, message: '请输入学校名称', trigger: 'blur' }
                ],
                sNetIp: [
                    { required: true, message: '请输入公网IP', trigger: 'blur' },
                    { pattern: /^(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))$/, message: '请输入正确的公网IP', trigger: 'blur' }
                ],
                sPort: [
                     { required: true, message: '请输入端口号', trigger: 'blur' },
                     { pattern: /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/, message: '请输入正确的端口号', trigger: 'blur' }
                ]
            }
        }
    },
    created() {
        console.log('val', this.updataData);
        // this.getSettlementConfigDetail(this.updataData.schoolId);
        // this.formInline = res
    },
    methods: {
        // 获取详情
        // getSettlementConfigDetail(schoolId){
        //     getSettlementConfigDetail(schoolId).then(res => {
        //         if (res.data.status == 200) {
        //             console.log('res', res);
        //         }
        //     });
        // },
        // 确定按钮
        updataBtn(updataData) {
            this.$refs[updataData].validate((valid) => {
                if (valid) {// 验证通过
                    this.loadingBtn=true;
                    updateSettlementConfig(this.updataData.pId, this.updataData.sNetIp, this.updataData.sPort).then(res => {
                        if (res.data.status==200) {
                            this.loadingBtn=false;
                            this.$message({
                                type: 'success',
                                message: '修改成功!'
                            });
                            this.$emit('searchList');// 更新列表
                            this.handleClose();
                        }
                    })
                } else {
                    return false;
                }
            });
        },

        handleClose() {
            this.delDialogAddTea();
        },
        // 取消按钮 
        resetForm(dataForm) {
            this.$refs[dataForm].resetFields();
            this.delDialogAddTea();
        },
        // 还原弹窗信息
        delDialogAddTea() {
            this.updataData.dialogUpdata = false;
        }
    }
}
</script>



